// Random.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int main(int argc, char* argv[])
{
	int u32_filesize = 1024;
	printf("Random Data(1K Bytes) Generator V1.0\nAuthor: Wilson Jiang QQ:8044997\n");
	printf("Usage: Random.EXE [filesize]\n");
	if (argc == 1)
	{
		printf("[filesize] is empty, default 1024 Bytes.\n");
		u32_filesize = 1024;
	}
	else if (argc == 2)
	{
		u32_filesize = atoi(argv[1]);
	}
	CTime	nowtime = CTime::GetCurrentTime();
	int u32_time = nowtime.GetTime();
	srand((unsigned) time(NULL));

	unsigned char *buff = new unsigned char[u32_filesize];

	for (int i=0; i<u32_filesize; i++)
	{
	//	Sleep(1);
		buff[i] = rand() % 255;
		printf("%.2X ",buff[i]);
		if (i%16 == 15)
		{
			printf("\r\n");
		}
	}

	LPCTSTR lpszFileName = new char[32];
	sprintf((char*)lpszFileName, "Random_%X.bin", u32_time);
	//*
	CFile log_txtfile;
	CFileException ex;
	
	if(!log_txtfile.Open(lpszFileName, CFile::modeCreate | CFile::modeReadWrite | CFile::shareDenyWrite | CFile::modeNoTruncate, &ex))
	{
		TCHAR szError[1024];
		ex.GetErrorMessage(szError, 1024);
		TRACE(szError);
	}
	else
	{
		log_txtfile.SeekToBegin();
		log_txtfile.Write(buff, u32_filesize);
		log_txtfile.Close();
	}
	//*/
	return 0;
}

